package com.romotc.qqrobot.webqq.util;

import java.util.Date;
import java.util.Random;

import org.apache.commons.lang.math.RandomUtils;

import com.romotc.qqrobot.webqq.WebQQConstant;

public class QQRandomUtil {


	/**
	 * webqq 接口连接后的r随机数 
	 * e.g:0.005160598549991846  0.005160598549991846 0.6083361646160483
	 *     0.009004837323960624                      0.3057260726818327
	 * @return
	 */
	public static double webQQRandom() {
		return RandomUtils.nextDouble();
	}
	
	/**
	 * 获取随即Clientid
	 * @return 10353456 8位整数
	 */
	public static String getRandomClientId(int clientIdLen) {
		int randomInt = RandomUtils.nextInt(100) - 1;
		long curTime = new Date().getTime();
		
		long lenParam = 1;
		for(int i = 0;i <= clientIdLen;i++) {
			lenParam *= 10;
		}
		
		curTime = curTime % lenParam;
//		String(k.random(0, 99)) + String((new Date()).getTime() % 1000000)
		return String.valueOf(randomInt + curTime);
	}
	
	/**
	 * 腾讯登录之前的pgv_pvid生成方式
	 * @return
	 */
	public static String getRandomPvid() {
		long pvid = RandomUtils.nextLong() % 10000000000L;
		return String.valueOf(pvid);
	}
	
	public static String getRandomSSid() {
		return getRandomPvid();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int a = 234;
		System.out.println(a % 100);
		for (int i = 0; i < 100; i++) {
			System.out.println(getRandomPvid());	
		}
		
	}
}  


	
